package com.test.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.test.dao.UserMapper;
import com.test.model.User;
/**
 * 
 * 
 * 
 * @author king
 * @since 2018年1月5日20:20:23
 */
@RestController
public class UserController {
	
	@Autowired
	UserMapper userMapper;
	
	
	//登录
	@RequestMapping("Login")
	public Map Logincotr(@RequestBody(required=false) User u){
		Map m=new HashMap();
		User u1=userMapper.selectByName(u.getName());
		if(null!=u1){
			if(u1.getPassword().equals(u.getPassword())){
				m.put("rs", "Y");
			}else{
				m.put("rs", "N1");
			}
		}else{
			m.put("rs", "N");
		}
		return m;
	}
	
	
	//注册
	@RequestMapping("Register")
	public Map Registercrol(@RequestBody User u){
		Map m=new HashMap();
		User u1=userMapper.selectByName(u.getName());
		if(null!=u1){
			m.put("rs", "N");
		}else{
			
			if(userMapper.insertSelective(u)>0){
				m.put("rs", "Y");
	
			}
			
		}
		
		return m;
	}
	
	
	
	
	
	

}
